package com.woniuxy.springbootthymeleaf.config;

import com.woniuxy.springbootthymeleaf.filter.CustomFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

/**
 * @author linke
 * @version 1.0
 * @className: FilterConfig
 * @description: 过滤器配置类
 * @date 2021/11/17 1:26
 */
@Configuration
public class FilterConfig {
    /**
     * 注册过滤器
     *
     * @return
     */
    @Bean
    public FilterRegistrationBean<CustomFilter> registrationBean(){
        FilterRegistrationBean bean = new FilterRegistrationBean();
        //注册过滤器
        bean.setFilter(new CustomFilter());
        //创建过滤url 参数
        List<String> urls = new ArrayList<>();
        urls.add("/*");
        urls.add("/order/*");
        //设置过滤的url  参数是集合类型
        bean.setUrlPatterns(urls);
        //设置执行顺序
        bean.setOrder(0);
        return bean;
    }



}
